package controller

import (
	"context"
	pb "gitee.com/micro-services/protocol/room/api"
	"micro.room.client/ao"
)

type RoomController struct{}

func (rc *RoomController) CreateRoom(ctx context.Context, r *pb.APICreateRoomReq, w *pb.APICreateRoomRsp) error {
	rsp, err := ao.CreateRoom(ctx, r)
	if err != nil {
		return err
	}

	w.Msg = rsp.Msg
	w.RetCode = rsp.RetCode
	return nil
}

func (rc *RoomController) UpdateRoomInfo(ctx context.Context, r *pb.APIUpdateRoomInfoReq, w *pb.APIUpdateRoomInfoRsp) error {
	rsp, err := ao.UpdateRoomInfo(ctx, r)
	if err != nil {
		return err
	}

	w.Msg = rsp.Msg
	w.RetCode = rsp.RetCode
	return nil
}

func (rc *RoomController) DeleteRoom(ctx context.Context, r *pb.APIDeleteRoomReq, w *pb.APIDeleteRoomRsp) error {
	rsp, err := ao.DeleteRoom(ctx, r)
	if err != nil {
		return err
	}

	w.Msg = rsp.Msg
	w.RetCode = rsp.RetCode
	return nil
}

func (rc *RoomController) BatchRoomInfo(ctx context.Context, r *pb.APIBatchRoomInfoReq, w *pb.APIBatchRoomInfoRsp) error {
	rsp, err := ao.BatchRoomInfo(ctx, r)
	if err != nil {
		return err
	}

	w.Info = rsp.Info
	return nil
}

func (rc *RoomController) RoomList(ctx context.Context, r *pb.APIRoomListReq, w *pb.APIRoomListRsp) error {
	rsp, err := ao.RoomList(ctx, r)
	if err != nil {
		return err
	}

	w.List = rsp.List
	w.Count = rsp.Count
	return nil
}
